package corej.course.net;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPClient {
    public static void main(String[] args) throws Exception {
        DatagramSocket ds = new DatagramSocket();
        String s = "I am here!";
        byte[] bs = s.getBytes();
        DatagramPacket letter1 = new DatagramPacket(bs, 0, bs.length,
                InetAddress.getLocalHost(), 10000);
        ds.send(letter1);

        byte[] bs2 = new byte[100];
        DatagramPacket receiveLetter = new DatagramPacket(bs2, 0, bs2.length);
        ds.receive(receiveLetter);

        byte[] bs3 = receiveLetter.getData();
        int offset = receiveLetter.getOffset();
        int length = receiveLetter.getLength();
        String text = new String(bs3, offset, length);
        System.out.println(text);

        ds.close();
    }

}
